package cn.kgc.commons.util;

/**
 * @description: 调用阿里api发短信
 * @author: 石浩杰
 * @date: 2022-11-01 13:43
 */
public class SendPhoneMessage {
    private static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config
                = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void sendPhoneMessage(String phone,String code) throws Exception{

        com.aliyun.dysmsapi20170525.Client client
                = createClient(
                "LTAI5tPewUVSCZkNXtqcXxEA",
                "7qgJU8SBxSzmdPrpjvuKWMa3rw3phl");


        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                .setSignName("我的大觅网在线售票系统")
                .setTemplateCode("SMS_190780823")
                .setPhoneNumbers(phone)
                .setTemplateParam("{\"code\":"+code+"}");

        com.aliyun.teautil.models.RuntimeOptions
                runtime = new com.aliyun.teautil.models.RuntimeOptions();

        client.sendSmsWithOptions(sendSmsRequest, runtime);
    }
}
